﻿using System;
using System.Xml.Linq;

using Perseus;

using Hetymine.Executioner.Controls;
using Hetymine.Executioner.Data;
using Hetymine.Executioner.Triggers;

namespace Hetymine.Executioner.Plugins.Triggers.Speech {
    public class SpeechTrigger : ITrigger {
        private SpeechTriggerConfigurator _Configurator;

        public SpeechTrigger() {
            this.Phrase = string.Empty;
        }

        public string Phrase { get; set; }

        #region ITrigger Members
        public bool IsEmpty {
            get { return (this.Phrase.IsEmpty()); }
        }
        public bool IsSelected { get; set; }

        public void Load(XElement element) {
            this.Phrase = element.Value;
        }
        public XElement Save() {
            if (this.IsEmpty) {
                return null;
            }

            XElement xe = new XElement("Speech");
            xe.Value = this.Phrase;

            return xe;
        }

        public IConfigurator<ITrigger> Configurator {
            get {
                if (this._Configurator == null) {
                    this._Configurator = new SpeechTriggerConfigurator();
                }
                this._Configurator.InitializeConfig(this);
                return this._Configurator;
            }
        }

        public object Clone() {
            SpeechTrigger t = (SpeechTrigger)this.MemberwiseClone();
            t._Configurator = null;
            return t;
        }
        #endregion
    }
}
